import React, { Component, createRef } from "react";

class App extends Component {
  file = createRef();

  submit = () => {
    console.log(this.file.current.files[0]);
  };

  render() {
    return (
      <>
        <h2>文件上传</h2>
        {/* 因为文件上传框是只读的，所以只能使用非受控组件 */}
        <input type="file" ref={this.file} />
        <button onClick={this.submit}>提交</button>
      </>
    );
  }
}

export default App;
